#include <iostream>
#include <pthread.h>
#include <string>
#include <ctime>


static int num = 1;

template<class T>
class Thread
{
private:
    static void* Running(void *args)
    {
        Thread* thread = static_cast<Thread*>(args);
        thread->Entry();
        return nullptr;
    }
public:

    typedef void (*callback_t)(T);

    Thread(callback_t cb,T data)
        :_tid(0),_name(""),_isrunning(false),_start_time(0),_cb(cb),_data(data)
    {}

    void Run()
    {
        _name = "thread-" + std::to_string(num++);
        _isrunning = true;
        _start_time = time(nullptr);

        pthread_create(&_tid,nullptr,Running,this);
    }

    void Entry()
    {
        _cb(_data);
    }

    void Join()
    {
        _isrunning = false;
        pthread_join(_tid,nullptr);
    }

    std::string GetName()
    {
        return _name;
    }

    uint64_t Start_Time()
    {
        return _start_time;
    }

    bool IsRunning()
    {
        return _isrunning;
    }

    ~Thread()
    {}

private:
    pthread_t _tid;
    std::string _name;
    bool _isrunning;
    uint64_t _start_time;

    T _data;
    callback_t _cb;
};